package com.wu.Controller;

import com.wu.DO.studentDO;
import com.wu.Service.StudentService;
import com.wu.Util.Const;
import com.wu.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;


/**
 * Created by admin on 2018/11/19.
 */
@Controller
@RequestMapping(value = "/Student")
public class StudentController {
    @Autowired
   private  StudentService studentService;
    @RequestMapping(value ="login",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<studentDO> login(String username, String password, HttpSession session){

        ServerResponse<studentDO> response= studentService.login(username,password);
        if(response.isSuccess()){
            session.setAttribute(Const.CURRENY_USER,response.getData());

        }
        return response;
    }
    @RequestMapping(value ="logout",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> logout(HttpSession session){
        session.removeAttribute(Const.CURRENY_USER);
        return ServerResponse.createBySuccess();
    }
    @RequestMapping(value="addStudent",method=RequestMethod.GET)
    @ResponseBody
    public ServerResponse<String> add(Integer studentId,String username,String password,String sname, String studentClass, String sex, String phoneNumber, String email, String identityNumber){
        ServerResponse<String> response=studentService.addStudent( studentId,username, password, sname,  studentClass, sex,  phoneNumber,  email,  identityNumber);
        return response;
    }

}
